<?php echo $this->Html->script('ckeditor/ckeditor');?>
<?php echo $this->Form->textarea('editor',array('class'=>'ckeditor'))?>

<input type="button" id="test" onclick="javascript:updateDiv();" value="test" >

<script>


	


CKEDITOR.plugins.registered['save'] = {
	      init: function (editor) {
	         var command = editor.addCommand('save',
	         {
	              modes: { wysiwyg: 1, source: 1 },
	              exec: function (editor) { // Add here custom function for the save button
	            	  var data = CKEDITOR.instances.editor.getData();
	            	  insert_data(data);
	              }
	         });
	         editor.ui.addButton('Save', { label: 'Save', command: 'save' });
	      }
	  }




	  

	  
function insert_data(data){

	$.ajax({
		url: url_base+"admin/update_noticia",
		type: "POST",
		data: {idnoticia:'1',text: data },	
    beforeSend: function(){ //mostra procesant en el dialog
			
	},
	success: function(data){
				//var data = jQuery.parseJSON(data);
				//CKEDITOR.instances.editor.setData(data);	
	    		alert("Canvis guardats");		
	}
	});
}


	  
function updateDiv(){

	//CKEDITOR.instances.editor.setData( '<p>hola</p>' );	

	$.ajax({
		url: url_base+"admin/get_noticia",
		type: "POST",
		data: { id_noticia: "1" },	
   			 beforeSend: function(){ //mostra procesant en el dialog
			},
		success: function(data){
					//var data = jQuery.parseJSON(data);
					CKEDITOR.instances.editor.setData(data);	
		    				
		}
	});
	
	

}


	  
</script>